package be.pluyckx.batteryprogress.activity.fragment.settings;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import be.pluyckx.batteryprogress.R;
import be.pluyckx.batteryprogress.application.Constants;
import be.pluyckx.batteryprogress.components.view.NumberPicker;
import be.pluyckx.batteryprogress.data.history.BatteryHistory;

/**
 * Created by Philip on 11/09/13.
 *
 * A settings Fragment which hold settings for the BatteryHistory.
 */
public class HistorySettings extends Fragment {
  private NumberPicker mNumberPicker;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_settings_history, container, false);

    mNumberPicker = (NumberPicker) view.findViewById(R.id.np_history_size);

    return view;
  }

  @Override
  public void onResume() {
    super.onResume();

    mNumberPicker.setValue(Constants.getHistorySize());
  }

  @Override
  public void onPause() {
    Constants.setHistorySize(mNumberPicker.getValue());
    BatteryHistory.getHistory().setSize(mNumberPicker.getValue());

    Log.d("RTSettings", "Preferences stored");

    super.onPause();
  }
}
